<div class="centershare">
    <div class="yundan">
        <div class="Ostep" >
            <ul>
                <li>我的仓库</li>
                <li class="os2">填写运输信息</li>
                <li class="os3">运单付款</li>
                <li class="os4">完成运单</li>
            </ul>
        </div>
        <form method="post" action="/member/waybillsubmit">
        <div class="OrderData">
            <div class="ODleft">
                运单信息
            </div>
            <div class="ODright">
                <div class="infobox">
                    <div class="Oinfo">
                        <h1>您本次共提交<span><?= $this->itemCount ?></span>个库存物品，物品重量为<span><?= $this->weight ?></span>g</h1>
                    </div>
                    <div class="baoguo">
                        <div class="bg">
                            <h2>预估包裹重量：<em><?= $this->weight + $this->bagWeight ?></em>g</h2><span>(打包后的重量,含包装箱重量.)</span><a href="http://help.uuch.com/?p=216">了解包裹重量？</a>
                        </div>
                        <?php if($this->volumeWeight >$this->weight + $this->bagWeight){ ?>
                        <div class="tj">
                            <h2>预估体积重量：<em><?= $this->volumeWeight ?></em>g</h2><span>(部分快递公司规定，结算重量时，取体积重量与实际重量两者中较大者进行结算。)</span>
                        </div>
                        <?php } ?>
                    </div>
                    <div class="jsts"><p><i></i>运单结算时根据预估重量收取运费，最终以实际重量为准，多收费用部分退还您的悠奇帐户！</p></div>
                    <div class="QDtable">
                        <table>
                            <tr>
                                <th class="q1">库存号</th>
                                <th class="q2">名称</th>
                                <th class="q3">物品净重</th>
                                <th class="q4">体积重量</th>
                            </tr>
                         <?php foreach ($this->items as $item){ ?><tr>
                                <td class="q1"><?= $item->Barcode ?></td>
                                <td class="q2"><?= $item->ProductName ?></td>
                                <td class="q3"><?= $item->Weight  ?>g</td>
                                <td class="q4"><?= $item->VolumeWeight?$item->VolumeWeight:'(无)'  ?></td></tr><?php   }?>
                         </table>
                    </div>
                    <div class="Ochange">
                        <a href="/member/mystore">返回仓库更改运单</a>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="OrderData">
            <div class="ODleft">
                收货信息
                <?= $this->formHidden('addressId',$this->default->Id) ?>
                <?= $this->formHidden('cityId',$this->default->State) ?>
            </div>
            <div class="ODright">
                <div class="dizhi"<?= $this->hasAddress?'':' style="display:none"' ?>>
                    <table>
                        <tr>
                            <td>收 货 人：</td>
                            <td id="c_linkMan"><?= $this->default->LinkMan ?></td>
                        </tr>
                        <tr>
                            <td>收货国家：</td>
                            <td id="c_stateText"><?= $this->default->StateText ?></td>
                        </tr>
                        <tr>
                            <td>收货地址：</td>
                            <td id="c_street"><?= $this->default->Street ?></td>
                        </tr>
                        <tr>
                            <td>邮　　编：</td>
                            <td id="c_postCode"><?= $this->default->Postcode ?></td>
                        </tr>
                        <tr>
                            <td>电　　话：</td>
                            <td id="c_mobile"><?= $this->default->Mobile ?></td>
                        </tr>
                    </table>
                </div>
                <div class="Ochange" <?= $this->hasAddress?'':' style="display:none"' ?>>
                    <a id="aOchange" href="javascript:void(0)">更改收货地址</a>
                </div>
                
                <div id="dizhichange" class="dizhichange"<?= $this->hasAddress?' style="display:none"':'' ?>>
                    <table class="changeHX">
                        <?php foreach ($this->address as $item) { ?>
                        <tr<?= $item->Id == $this->default->Id?' class="changeON"':'' ?>>
                            <td class="dzcz">
                                <input class="useaddr" name="useaddr"<?= $item->Id == $this->default->Id?' checked="true"':'' ?> type="radio" value="<?= $item->Id ?>" />
                                <input class="useState" type="hidden" value="<?= $item->State ?>"/>
                            </td>
                            <td>
                                <p><span class="s_street"><?= $item->Street ?></span>，邮编：<span class="s_postCode"><?= $item->Postcode ?></span></p>
                                <p>收货人：<span class="s_linkMan"><?= $item->LinkMan ?></span>，电话：<span class="s_mobile"><?= $item->mobile ?></span> 国家：<span class="s_stateText"><?= $item->StateText ?></span></p>
                            </td>
                        </tr>                            
                        <?php }?>
                        <tr>
                            <td class="dzcz"><input id="usenew" class="useaddr" name="useaddr"<?= $this->hasAddress?'':' checked="true"' ?> type="radio" value="<?= $item->Id ?>" /></td>
                            <td>
                                <p>使用新地址</p>
                            </td>
                        </tr>
                    </table>
                    <div class="newdz"<?= $this->hasAddress?' style="display:none"':'' ?>>
                        <table>
                                <tr>
                                    <td class="new_z"><span>*</span>所在国家：</td>
                                    <td>
                                        <div class="guojiabox">
                                            <div class="guyojiatext"><input type="text" readonly="readonly" id="stateText" name="stateText" /><a href="javascript:void(0)"></a></div>
                                            <input type="hidden" class="state" id="state" name="state" />
                                            <div class="guojiaceng" style="display:none;">
                                                <div class="remen">
                                                    <h2>热门国家和地区</h2>
                                                    <ul class="countrylist">
                                                        <li><a href="#" id="c_us" cid="1">美国</a></li>
                                                        <li><a href="#" cid="2">加拿大</a></li>
                                                        <li><a href="#" cid="3">澳大利亚</a></li>
                                                        <li><a href="#" cid="47">日本</a></li>
                                                        <li><a href="#" cid="39">台湾</a></li>
                                                        <li><a href="#" cid="4">新西兰</a></li>
                                                        <li><a href="#" cid="5">英国</a></li>
                                                        <li><a href="#" cid="42">马来西亚</a></li>
                                                    </ul>
                                                </div>
                                                <div class="allcountry">
                                                    <h2>全部国家和地区</h2>
                                                    <ul class="countryzm">
                                                        <?php
                                                        foreach ($this->words as $char){
                                                        ?>
                                                        <li <?= $char=='A'?'class="zmon"':'' ?>><a href="#"><?= $char ?></a></li>
                                                        <?php } ?>

                                                    </ul>
                                                    <div id="countryTab">
                                                    <?php
                                                    foreach ($this->words as $char){
                                                    ?>
                                                <ul class="countrylist"  <?= $char=='A'?'':'style="display:none"' ?>>
                                                    <?php
                                                    $citys= Application_Model_city::GetBySortCode($char);
                                                    foreach ($citys as $city){
                                                    ?>
                                                        <li><a href="#" cid="<?= $city->Id ?>"><?= $city->Name ?></a></li>
                                                        <?php } ?>
                                                    </ul>
                                                    <?php
                                                        }
                                                    ?>
                                                    </div>
                                                </div>
                                                
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="new_z"><span>*</span>详细地址：</td>
                                    <td><input class="text400 " name="street" maxlength="500" id="street" type="text" /><br />(英语地址,请包含州(省),城市)</td>
                                </tr>
                                <tr>
                                    <td class="new_z"><span>*</span>邮政编码：</td>
                                    <td><input class="text" name="postCode" maxlength="20" id="postCode" type="text" /></td>
                                </tr>
                                <tr>
                                    <td class="new_z"><span>*</span>收货人：</td>
                                    <td><input class="text " name="linkMan" maxlength="50" id="linkMan" type="text" /></td>
                                </tr>
                                <tr>
                                    <td class="new_z"><span>*</span>联系电话：</td>
                                    <td><input class="text " name="mobile" id="mobile" maxlength="20" type="text " />
                                    </td>
                                </tr>
                            </table>
                    </div>
                    <div class="changeok">
                          <a class="baocun" href="#"><span>确定</span></a><a class="quxiao" href="#"><span>取消</span></a>
                    </div>
                </div>
            </div>
        </div>
            <div class="OrderData">
                <p style="margin: 5px 8px;font-family: Arial;color: #f60;font-size: 14px;">温馨提示：近期海关严查，所有货件在出港环节都会有一周左右的延误，详情请留意网站公告，谢谢！</p>
            </div>
        <div class="OrderData">
            <div class="ODleft">
                配送方式
            </div>
            <div class="ODright">
                <div class="kuaidi">
                    <?php if($this->hasAddress){ ?>
                    <table>
                        <tr>
                            <th class="kd1">快递方式选择</th>
                            <th class="kd2">受理情况</th>
                            <th class="kd3">是否按<br />体积重量</th>
                            <th class="kd4">结算重量</th>
                            <th class="kd5">预计天数</th>
                            <th class="kd6">金额(￥)</th>
                        </tr>
                        <?php 
                        $showItem= function($item,$view){
                            $accept =true;
                            $message ='';
                            foreach ($view->items as $si){
                                $itemAccept =$item->isAccept($si->ItemType);
                                if((!$itemAccept) && !strpos($message,$si->getItemTypeName())){
                                    $message .= ' 不接受'.$si->getItemTypeName();
                                }
                                $accept = $accept && $itemAccept;
                            }
                            //如果大于2000，Air不接受
                            if($item->Express->MaxWeight > 0 && $view->SumWeight > $item->Express->MaxWeight){
                                $accept = FALSE;
                                $message .= ' 不接受大于'. ($item->Express->MaxWeight/1000) .'KG的包裹';
                            }
                            if($item->SortKey !== false){
                                //如果后台没有设置对应价格不让选择
                        ?>
                        <tr>
                            <td class="kd1">
                                <label>
                                    <input data="<?= $item->Express->ReportFee ?>" type="radio" <?= $accept?'':' disabled="disabled"' ?> class="shiptyperadio" value="<?= $item->ExpressId?>" name="shipType" />
                                    <span><?= $item->getExpress()->Name ?></span>
                                    <?php if ($item->Express->Id == 37 && $view->isAbCoupon) { ?>
                                        <br><font style="color: #c00;margin-left: 30px;">可用首重减免券</font>
                                    <?php } ?>
                                </label>
                            </td>
                            <td class="kd2"><?= $message?"<span>$message</span>":'可受理' ?></td>
                            <td class="kd3"><?= $item->Express->IsVolume?'是':'<p style="color:green">否</p>' ?></td>
                            <td class="kd4"><?= $item->Express->IsVolume&& $view->volumeWeight> $view->SumWeight? $view->volumeWeight : $view->SumWeight ?>g</td>
                            <td class="kd5"><?=  $item->times?><input type="hidden" id="isRemoteFee" name="isRemoteFee" value="<?php echo $item->Express->IsRemoteFee;?>" />工作日</td>
                            <td class="kd6"><?= number_format($item->SortKey,2) ?></td>
                        </tr>
                        <?php } ?>
                        <?php }; ?>
                        <?php
                             foreach ($this->prices as $item){
                                 $weight=0;
                                 if($item->Express->IsVolume && $this->volumeWeight>$this->SumWeight)
                                     $weight = $this->volumeWeight;
                                 else
                                     $weight = $this->SumWeight;
                                 if($this->isReceive){
                                     $item->SortKey = "0.01";
                                 } else {
                                    $item->SortKey = $item->getMoneyByweight($weight);
                                 }
                             }
                             $prices = Uuch_Util::quickSort($this->prices, 'SortKey');
                             $air = NULL;
                             foreach($prices as $item){   
                                 
                                 //被禁止
                                 if($item->Express->isDisable == 1){ 
                                     continue;
                                 }
                                 //东西马
                                 if($this->isEast){
                                     if($item->ExpressId == Application_Model_Express::Express_WesternA || $item->ExpressId == Application_Model_Express::Express_WesternB){
                                         continue;
                                     }
                                 } else {
                                     if($item->ExpressId == Application_Model_Express::Express_EastA || $item->ExpressId == Application_Model_Express::Express_EastB){
                                         continue;
                                     }
                                 }
                                 if($this->isReceive){
                                    if($item->ExpressId == Application_Model_Express::Expredd_ReceiveUser){
                                       $showItem($item,$this);
                                       continue;
                                    }
                                 }else {
                                    //跳过AIR，在最后面补上
                                   if($item->Express->MaxWeight == 2000){
                                       continue;;
                                   }
                                   $showItem($item,$this);  
                                 }
                            }
                            foreach($prices as $item){
                                
                                 //被禁止
                                 if($item->Express->isDisable == 1){ 
                                     continue;
                                 }
                                if($item->Express->MaxWeight == 2000){
                                    $showItem($item,$this);       
                                }
                            } 
                        ?>
                    </table>
                    <?php } ?>
			<h4><i></i>温馨提示：选择中邮小包运送周期长、丢包率高、物流跟踪不畅，如急用或贵重物品请慎重选择！</h4>
                </div>
            </div>
        </div>
        
        <div class="OrderData">
            <div class="ODleft">
                增值服务
            </div>
            <div class="ODright">
                <div class="tese">
                    <ul>
                    	<li>
                        	<label><input id="isNoPackage" name="isNoSkin" type="checkbox" value="1" />去掉物品非必要包装<span>[免费]</span></label>
                            <p>此项操作可以缩减包裹的重量和体积，节省运费，非必要包装如：鞋盒、填充物等！</p>
                        </li>
                    	<li>
                        	<label><input id="isNoLogo" name="isNoLogo" type="checkbox" value="1" />取出商品吊牌/发票<span>[服务费:+20元]</span></label>
                            <p>此项可避免海关根据标价收取关税，还能减小被认定为商业包裹的几率。</p>
                        </li>
                        <?php if($this->isFragile){ ?>
                        <li>
                        	<label><input id="isFragile" name="isFragile" type="checkbox" value="1" />对易碎物品进行气泡膜防震处理<span>[费用:+<?php echo $this->fragileFee;?>元]</span></label>
                            <p>由于包裹远渡重洋，物品极易破损，强烈建议选择！</p>
                            <input type="hidden" id="fragileFee" name="fragileFee" value="<?php echo $this->fragileFee;?>" />
                        </li>
                        <?php } ?>
                    	<li>
                        	<label><input id="isKong" name="isCompress" type="checkbox" value="1" />真空压缩服务，减少体积重量<span>[服务费:+20元]</span></label>
                            <p>使用压缩服务后节省金额如小于10元此项不收费。</p>
                        </li>
                    	<li>
                        	<label><input id="isWooden" name="isWooden"  type="checkbox" value="1" />护角加固服务，减少易碎品破损率<span>[费用:+50元]</span></label>
                            <p>费用包含材料费、操作费！</p>
                        </li>
                    </ul>
                    
                </div>
            </div>
        </div>
        
        <div class="OrderData">
            <div class="ODleft">
                申报信息
            </div>
            <div class="ODright">
            	<div class="sbao">
                    <table>
                        <tr>
                            <td class="fyz">包裹申报价值：</td>
                            <td>
                            	<div class="sbinput">
                                    <input type="text" name="reportValue" class="number" id="reprotValue" />
                                    <i>输入美元价值</i>
                                    <span>USD($)</span>
                                </div>
                                <div class="sbjz">
                                	<p>海关对包裹收取关税的依据，申报过低可能罚款，申报过高则可能会缴纳更多关税！<a target="_blank" href="http://help.uuch.com/?p=494">申报技巧</a></p>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="fyz">购买保险：</td>
                            <td>
                            	<div class="baoxian">
                                    <ul>
                                        <li><label><input name="isPremium" class="isPremium" id="isPremium1" type="radio" value="1" />是</label></li>
                                        <li><label><input name="isPremium" class="isPremium" checked="checked" id="isPremium2" type="radio" value="0" />否</label></li>
                                        <li><a href="http://help.uuch.com/?p=492" target="_blank">关于保险？</a></li>
                                    </ul>
                                </div>
                                <div class="baoxiangm" style="display:none">
                                	<ul>
                                    	<li>
                                            <label>保险种类：</label>
                                            <span>收取投保价值的3%作为保费</span>
                                        </li>
                                        <li>
                                        	<label>投保价值：</label>
                                            <div class="tbje">
                                                <input type="text" name="PremiumValue" class="number" id="PremiumValue" /><i>人民币</i><span>元(￥)</span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        
        <div class="OrderData">
            <div class="ODleft">
                备注
            </div>
            <div class="ODright">
				<div class="tese">
                    <p style="margin-bottom:10px;">清关税号: <?= $this->formText('dutyNo') ?><span style="color:#ccc">(可不填,如填写,有利于帮您快速清关,德国,巴西等部分国家不填将不能正常发货)</span></p>
                	<?= $this->formTextarea('remark',null,array('cols'=>80,'rows'=>'5')) ?>
                    <?= $this->formHidden('isEuro',$this->isEuro) ?>
                    <p style="color:gray">您可在备注里面写上您的一些特殊要求</p>
                </div>
            </div>
        </div>
            
        <div class="OrderData">
            <div class="ODleft">
                收费详情
            </div>
            <div class="ODright">
                <div class="feiyong">
                    <table>
                        <tr>
                            <td class="fyz">运　　　费：</td>
                            <td><label id="shipFee"><?= $this->hasAddress?$prices[0]->SortKey:'0'?></label>元</td>
                        </tr>
                        <tr id="removalRow" style="display:none">
                            <td class="fyz">吊牌取出费：</td>
                            <td><label id="removalsFee">20.00</label>元</td>
                        </tr>
                        <tr id="compressRow" style="display:none">
                            <td class="fyz">真空压缩费：</td>
                            <td><label id="compressFee">20.00</label>元</td>
                        </tr>
                        <tr id="FragileRow" style="display:none">
                            <td class="fyz">易碎防震费：</td>
                            <td><label id="FragileFee"><?php echo number_format($this->fragileFee,2);?></label>元</td>
                        </tr>
                        <tr id="woodenRow" style="display:none">
                            <td class="fyz">护角加固费：</td>
                            <td><label id="woodenFee">50.00</label>元(护角加固会增加预计打包重量500g和预计打包体积5%)</td>
                        </tr>
                        <tr id="premiumRow" style="display:none">
                            <td class="fyz">保　　　费：</td>
                            <td><label id="premiumFee">0.00</label>元</td>
                        </tr>
                        <?php if($this->cnShipFee && $this->cnShipFee>0){ ?>
                        <tr>
                            <td class="fyz">国 内 运 费：</td>
                            <td><label id="cnShipFeeLabel"><?= number_format($this->cnShipFee,2) ?></label>元</td>
                        </tr>
                        <?php } ?>
                        <tr id="remoteFeeRow" style="display:none">
                            <td class="fyz">偏　远　费：<?= $this->formHidden('foRemoteFee',Application_Model_RemoteFee::remoteFee) ?></td>
                            <td><label id="remoteFee">80.00<?= $this->formHidden('isZipRemoteFee',$this->isZipRemoteFee) ?></label>元</td>
                        </tr>
                        <tr id="coupon_row" style="display:none">
                            <td class="fyz">优　惠　券：</td>
                            <td><em>-0.00元</em><?= $this->formHidden('cnShipFee',$this->cnShipFee) ?></td>
                        </tr>
                        <tr id="activity_row" style="display:none">
                            <td class="fyz">活 动 折 扣：</td>
                            <td><label id="activityFee">0</label></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        
        <div class="accounts_num">
                <table>
                    <tr>
                        <td class="preferential">
                            <ul>
                                <li>
                                    <h3><a href="#" id="coupon_open">(+)使用优惠卷抵消部分总额</a></h3>
                                    <div id="coupon_enter" class="offset" style="display:none;">
                                        <div class="offset_t">
                                            <h4>提示：优惠卷每次只能使用1张！</h4><a id="coupon_close" href="#">关闭</a>
                                        </div>
                                        <div class="offset_z">
                                            <h4>请选择要使用的优惠券：</h4>
                                            <dl>
                                                <dd><label><input class="couponno" name="couponno" data="0" checked="checked" type="radio" value="0" />[不使用优惠券]</label></dd>
                                                <?php foreach($this->coupons as $coupon){ 
                                                    if($coupon->DateExpired < date('Y-m-d')){
                                                        continue;
                                                    }
                                                    ?>
                                                <?php //echo $coupon->batchNo;//var_dump($coupon)//echo $coupon->bathNo;//; ?>
                                                <dd class="<?php echo $coupon->batchNo ?>"><label><input class="couponno" data="<?= $coupon->getDiscountMoney() ?>" name="couponno" type="radio" value="<?= $coupon->No ?>" /><?= $coupon->Title ?></label></dd>
                                                <?php } ?>
                                            </dl>
                                        </div>
                                        <div class="huode">
                                            <span>您使用了 <em id="cou_count">0</em> 张优惠券　可以优惠 <em id="cou_money">0.00</em> 元</span>
                                        </div>
                                    </div>
                                </li>
                            </ul>                           
                        </td>
                        <td class="total"><span>应付总额：</span><em id="amount">￥0.00</em><span>元</span></td>
                    </tr>
                </table>
        </div>
        <div class="Order_ok">
            <dl>
                <dt>
                    <div class="Qbz" style="display:none;">您选择了去掉物品非必要包装，此项节省的钱将返回您的RMB帐户！</div>
                </dt>
                <dd><input name="btn_submit" value="" id="btn_submit" type="submit" onmouseover="this.className='Order_After'" onmouseout="this.className=''" /></dd>
            </dl>
            
        </div>
        </form>
        
    </div>
</div>
<script type="text/javascript">
$(function(){    
    $('#btn_submit').click(function(){
        if($('#addid').val()=='' || $('#dizhichange').is(':visible')){
            alert('请保存您的收货地址后再提交国际运单。');
            return false;
        }
        if($('.shiptyperadio:checked').length == 0){
            alert('请选择可以的配送方式。');
            return false;
        }
        $('#f_waybill').submit();
    });
    $('#aOchange').click(function(){
         $('#dizhichange').show();
        $('.dizhi,.Ochange').hide();
        return false;
    });
    //---国家选择器---
    $('.guojiabox').hover(function(){
        //$('.guojiaceng').show();
    },function(){
        $('.guojiaceng').hide();
    });
    $('.guyojiatext').click(function(){
        $('.guojiaceng').show();
    });
    $('.countrylist a').bind('click',function(){
        var city =$(this).text();
        $('#stateText').val(city);
        
        $('.guojiabox #state').val($(this).attr('cid'));
        $('.guojiaceng').hide();
        return false;
    });
    $('.countryzm a').each(function(index,item){
        $(item).click(function(){
            $('.countryzm li.zmon').removeClass('zmon');
            $(this).parent().addClass('zmon');
            $('#countryTab ul').hide();
            $('#countryTab ul').eq(index).show();
            return false;
        });
    });
    
    $('.useaddr').live('change',function(){
        if($('#usenew').is(':checked')){
            $('.newdz').show();
        }else{
            $('.newdz').hide();
        }
        $('.changeON').removeClass('changeON');
        $(this).parents('tr').addClass('changeON');
    });
    function validAddress(){
        if($('#state').val()==''){
            alert('请选择国家');
            $('#state').focus();
            return false;
        }
        if($('#street').val()==''){
            alert('请输入详细地址');
            $('#street').focus();
            return false;
        }
        if($('#postCode').val()==''){
            alert('请输入邮编');
            $('#postCode').focus();
            return false;
        }
        if($('#linkMan').val()==''){
            alert('请输入收货人');
            $('#linkMan').focus();
            return false;
        }
        if($('#mobile').val()==''){
            alert('请输入电话');
            $('#mobile').focus();
            return false;
        }
        return true;
    }
    $('.baocun').click(function(){
        var posts= {};
        $('.kuaidi table').css('visibility','hidden');
        if($('#usenew').is(':checked')){
            if(!validAddress()){
                return false;
            }
            
            var html = '<tr class="changeON">'
                         +   '<td class="dzcz">'
                         +  '<input class="useaddr" name="useaddr" checked="true" type="radio" value="" />'
                         +       '<input class="useState" type="hidden" value=""/>'
                         +   '</td>'
                         +  '<td>'
                         +       '<p><span class="s_street"></span>，邮编：<span class="s_postCode"></span></p>'
                         +       '<p>收货人：<span class="s_linkMan"></span>，电话：<span class="s_mobile"></span> 国家：<span class="s_stateText"></span></p>'
                         +   '</td>'
                         +'</tr>';
            $('.changeHX tr').eq(0).before(html);
            var newrow = $('.changeHX tr').eq(0);
            $('.newdz :input').each(function(index,item){
                posts[$(item).attr('name')]=$(item).val();
            });
            for(var item in posts){
                $('#c_'+item).text(posts[item]);
            }
            for(var item in posts){
                newrow.find('.s_'+item).text(posts[item]);
            }
            
            $.post('/member/newaddress', posts, function(data){
                $('.kuaidi').html(data);
                $('#isEuro').val($('#isEuro2').val());
                if($('#isEuro').val()){
                    $('#eoridiv').show();
                }else{
                    $('#eoridiv').hide();
                }
                $("#isZipRemoteFee").val($('#isZipRemoteFee2').val());
                newrow.find('.useaddr').val($('.kuaidi #newAddressId').val());
                $('.shiptyperadio:enabled').first().click();
                $('#addressId').val($('.kuaidi #newAddressId').val()); 
            }, 'html');            
            $('.newdz').hide();
        }else{
            $('.useaddr:checked').parents('tr').find('span').each(function(index,item){
                posts[$(item).attr('class').substr(2)]=$(item).text();
            });
            $('.kuaidi').append('正在获取运费,请稍等...');
            for(var item in posts){
                $('#c_'+item).text(posts[item]);
            }
            $.post('/member/cultfee', {'address':$('.useaddr:checked').val(),'isWooden':$('#isWooden').is(':checked')}, function(html){
                $('.kuaidi').html(html);
                $('#isEuro').val($('#isEuro2').val());
                if($('#isEuro').val()){
                    $('#eoridiv').show();
                }else{
                    $('#eoridiv').hide();
                }
                $("#isZipRemoteFee").val($('#isZipRemoteFee2').val());
                $('.shiptyperadio:enabled').first().click();
                $('#addressId').val($('.useaddr:checked').val());                
            }, 'html');        
        }                
        $('#dizhichange').hide();
        $('.dizhi,.Ochange').show();  
        return false;
    });
    
    $('.shiptyperadio').live('change',function(){
        var shipfee = $(this).parents('tr').find('.kd6').text();
        
        $('#shipFee').text(shipfee);        
        var reportFee = parseInt($(this).attr('data'));
        if(isNaN(reportFee))
            reportFee =0;
        $('#show_reportFee').text(changeTwoDecimal_f(reportFee) );
        cultAmount();
    });
    
    function changeTwoDecimal_f(x)
    {   
        var f_x = parseFloat(x);
        if (isNaN(f_x))
        {
            return x;
        }
        f_x = Math.round(f_x*100)/100;
        var s_x = f_x.toString();
        var pos_decimal = s_x.indexOf('.');
        if (pos_decimal < 0)
        {
            pos_decimal = s_x.length;
            s_x += '.';
        }
        while (s_x.length <= pos_decimal + 2)
        {
            s_x += '0';
        }
        return s_x;
    }
    
    function cultAmount(){
        var shipfee = $('.shiptyperadio:checked').parents('tr').find('.kd6').text().replace(',','').replace(',','');
        var isRemoteFee = $('.shiptyperadio:checked').parents('tr').find('#isRemoteFee').val();
        var isZipRemoteFee = $("#isZipRemoteFee").val();
        var reportFee = 0;
        var data = $('.couponno:checked').attr('data');
        var fragileFee = $("#fragileFee").val();
        var shipId = $(".shiptyperadio:checked").val();
        if(data != 0){
            $.post('/member/validatecoupon', {'couponno':$('.couponno:checked').val(),'money':shipfee,'shipId':shipId}, function(result){
                if(!result.result){
                    alert(result.message);
                    $(".couponno[data='0']").attr("checked","checkded");
                    cultAmount();
                }else{
                    $('#coupon_row em').text('-'+changeTwoDecimal_f(result.discount));
                    var compressFee = $('#isKong').is(':checked')?20:0;
                    var removalFee = $('#isNoLogo').is(':checked')?20:0;
                    var woodenFee = $('#isWooden').is(':checked')?50:0;
                    var Fragile = $('#isFragile').is(':checked')?fragileFee:0;
                    var foRemoteFee = 0;
                    if(isRemoteFee == 1 && isZipRemoteFee) {
                        foRemoteFee = $("#foRemoteFee").val(); //偏远费
                        $("#remoteFeeRow").show();
                    } else {
                        $("#remoteFeeRow").hide();
                    }
                    var premiumFee = 0;
                    if($('#isPremium1').is(':checked')){
                        premiumFee = parseFloat($('#premiumFee').text());
                    }
                    var money = parseFloat(shipfee) - parseFloat(result.discount) + reportFee + parseFloat($('#cnShipFee').val()) + compressFee + removalFee + woodenFee + parseFloat(Fragile) + premiumFee + parseFloat(foRemoteFee);
                    
                    if(money<0){
                        money=0;
                    }
                    /*马年端午活动开始*/
                    if(<?php echo $this->isHorseWuanwu;?>){
                        if(money >= 500 && money < 1000 ){
                            var discount = money*0.05;
                            money = money * 0.95;
                            $("#activityFee").text("-"+changeTwoDecimal_f(discount)+"元(9.5折)");
                            $("#activity_row").show();
                        } else if (money >= 1000){
                            var discount = money*0.1;
                            money = money * 0.9;
                            $("#activityFee").text("-"+changeTwoDecimal_f(discount)+"元(9折)");
                            $("#activity_row").show();
                        } else {
                            $("#activity_row").hide();
                        }
                    }
                    /*马年端午活动结束*/
                    $('#amount').text('￥'+ changeTwoDecimal_f(money));
                    $('#cou_count').text('1');
                    $('#cou_money').text(changeTwoDecimal_f(result.discount));
                }
            }, 'json').fail(function(){alert('验证出错了,请联系客服');});
        }else{
            $('#coupon_row em').text('-'+changeTwoDecimal_f(0));
            var compressFee = $('#isKong').is(':checked')?20:0;
            var removalFee = $('#isNoLogo').is(':checked')?20:0;
            var woodenFee = $('#isWooden').is(':checked')?50:0;
            var Fragile = $('#isFragile').is(':checked')?fragileFee:0;
            var foRemoteFee = 0;
            if(isRemoteFee == 1 && isZipRemoteFee) {
                foRemoteFee = $("#foRemoteFee").val(); //偏远费
                $("#remoteFeeRow").show();
            } else {
                $("#remoteFeeRow").hide();
            }
            var premiumFee = 0;
            if($('#isPremium1').is(':checked')){
                premiumFee = parseFloat($('#premiumFee').text());
            }
            var money = parseFloat(shipfee) - parseFloat(0) + reportFee+ parseFloat($('#cnShipFee').val())+ compressFee + removalFee + woodenFee + parseFloat(Fragile) + premiumFee + parseFloat(foRemoteFee);
            /*马年端午活动开始*/
            if(<?php echo $this->isHorseWuanwu;?>){
                if(money >= 500 && money < 1000 ){
                    var discount = money*0.05;
                    money = money * 0.95;
                    $("#activityFee").text("-"+changeTwoDecimal_f(discount)+"元(9.5折)");
                    $("#activity_row").show();
                } else if (money >= 1000){
                    var discount = money*0.1;
                    money = money * 0.9;
                    $("#activityFee").text("-"+changeTwoDecimal_f(discount)+"元(9折)");
                    $("#activity_row").show();
                } else {
                    $("#activity_row").hide();
                }
            }
            /*马年端午活动结束*/
            $('#amount').text('￥'+ changeTwoDecimal_f(money));
            if(changeTwoDecimal_f(money)>100){
                $('.Joinconfrim').show();
            }else{
                $('.Joinconfrim').hide();
            }
            $('#cou_count').text('0');
            $('#cou_money').text('0.00');
        }
        
    }
    $('.shiptyperadio:enabled').first().click();
    
    $('#coupon_open').click(function(){
        $('#coupon_enter').toggle();
        $('#coupon_row').show();
        return false;
    });
    $('#coupon_close').click(function(){
        $('#coupon_enter').hide();
        return false;
    });
    $('.couponno').change(function(){
        cultAmount();
    });
    
    $('#isNoPackage,#isKong').change(function(){
        if($(this).is(':checked')){
            $(this).parents('td').next().children().show();
        }else{
            $(this).parents('td').next().children().hide();
        }
    });
    
    $(':text').keypress(function(){
        $(this).next('i').hide();
    }).blur(function(){
        if($(this).val()===''){
            $(this).next('i').show();
        }
    });
    $('.sbao i').click(function(){
        $(this).prev(':text').focus();
    } );
    $('.isPremium').click(function(){
        if($('.isPremium:checked').val()==='1'){
            $('.baoxiangm').show();
            $('#premiumRow').show();
        }else{
            $('.baoxiangm').hide();
            $('#premiumRow').hide();
        }
    });
    $('#isKong').click(function(){
        if($(this).is(':checked')){
            $('#compressRow').show();
        }else{
            $('#compressRow').hide();
        }
        cultAmount();
    });
    $('#isNoLogo').click(function(){
        if($(this).is(':checked')){
            $('#removalRow').show();
        }else{
            $('#removalRow').hide();
        }
        cultAmount();
    });
    $('#isWooden').click(function(){
        if($(this).is(':checked')){
            $('#woodenRow').show();
        }else{
            $('#woodenRow').hide();
        }
//        $('.baocun').click();
        cultAmount();
    });
    $("#isFragile").click(function(){
        if($(this).is(':checked')){
            $('#FragileRow').show();
        }else{
            $('#FragileRow').hide();
        }
        cultAmount();
    });
    $('#PremiumValue,#reprotValue').keypress(function(e){
        if((e.keyCode < 48 || e.keyCode >57) && e.keyCode != 8 && e.keyCode !=127 ){
            return false;
        }
    });
    $('#PremiumValue').change(function(){
        $('#premiumFee').text(changeTwoDecimal_f($(this).val()*0.03));
        cultAmount();
    });
});
</script>
